package com.woniuxy.education.controller;

import com.woniuxy.education.entity.SelectStuData;
import com.woniuxy.education.entity.SelectStuDataPage;
import com.woniuxy.education.entity.TongJiTuData;
import com.woniuxy.education.service.SelectStuDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@CrossOrigin
@RestController
@Controller
public class SelectStuDataController {
    @Autowired
    SelectStuDataService selectStuDataService;
    //初始化查询条件
    @RequestMapping("/selectStuData")
    public SelectStuData sData1(){
        SelectStuData selectStuData=new SelectStuData();

        Map<Integer, List<Integer>> map=new HashMap<>();//<年级，班级（list集合）>
        int[] grades={1,2,3};
        for (int i=0;i<3;i++) {
            int grade=grades[i];
            map.put(grade, selectStuDataService.selectsClass(grade));
        }
        List<String> lists=new ArrayList<>();
        Set<Map.Entry<Integer, List<Integer>>> set = map.entrySet();
        for (Map.Entry<Integer, List<Integer>> entry : set) {
            Integer key = entry.getKey();
            String key1="";
            if(key.intValue()==1){
                key1=Integer.toString(key);
               key1="一";
            }
            else if(key.intValue()==3){
                key1=Integer.toString(key);
               key1="三";
            }
            else if(key.intValue()==2){
                key1=Integer.toString(key);
               key1="二";
            }
            List<Integer> list = entry.getValue();
            for(int i=0;i<list.size();i++){
                Integer value = list.get(i);
                lists.add("高"+key1+value+"班");
            }
        }
        String sn="";
        String snd=null;
        int i=1;
        for(String s:lists) {
            sn=sn+"{value: "+"'"+i+"'"+", label: "+"'"+s+"'"+" },";
            i++;
        }
        snd="["+sn+"]";
        selectStuData.setGradeclass(snd);




        //考试类型
        String tn=null;
        tn="["+"{value: "+"'高一上第一次月考'"+", label: "+"'高一上第一次月考'"+" },"+
                "{value: "+"'高一上第二次月考'"+", label: "+"'高一上第二次月考'"+" },"+
                "{value: "+"'高一上第三次月考'"+", label: "+"'高一上第三次月考'"+" },"+
                "{value: "+"'高一上期末考试'"+", label: "+"'高一上期末考试'"+" },"+
                "{value: "+"'高一下第一次月考'"+", label: "+"'高一下第一次月考'"+" },"+
                "{value: "+"'高一下第二次月考'"+", label: "+"'高一下第二次月考'"+" },"+
                "]";
        selectStuData.setTestName(tn);

        //科目
        String sub=null;
        sub="["+"{value: "+"'chinese'"+", label: "+"'语文'"+" },"+
                "{value: "+"'math'"+", label: "+"'数学'"+" },"+
                "{value: "+"'english'"+", label: "+"'外语'"+" },"+
                "{value: "+"'physical'"+", label: "+"'物理'"+" },"+
                "{value: "+"'chemical'"+", label: "+"'化学'"+" },"+
                "{value: "+"'biological'"+", label: "+"'生物'"+" },"+
                "{value: "+"'political'"+", label: "+"'政治'"+" },"+
                "{value: "+"'history'"+", label: "+"'历史'"+" },"+
                "{value: "+"'geographic'"+", label: "+"'地理'"+" },"+
                "]";
        selectStuData.setSubject(sub);
        return selectStuData;
    }
    //分页查询学生分数等数据
    @RequestMapping("/selectStuData1")
    public SelectStuDataPage sData2(String grades,String testNames,String subject,String pageindex){
        System.out.println(pageindex);
        //转int
        int grades1=Integer.parseInt(grades);
        int currentPage=Integer.parseInt(pageindex);

        SelectStuDataPage s1 =selectStuDataService.selectsStuGrade(grades1, testNames, subject,currentPage);
        return s1;
    }
    //查询统计图所需数据
    @RequestMapping("/selectStuData2")
    public TongJiTuData sData3(String grades, String testNames, String subject){
        //转int
        int grades1=Integer.parseInt(grades);
        int grade=selectStuDataService.selectsGrade(grades1);//grade年级
        TongJiTuData t=selectStuDataService.selectsClass1(grade,testNames,subject);
        return t;
    }
    //查询班级对比统计图所需数据
    @RequestMapping("/selectStuData3")
    public TongJiTuData sData4(String grades, String subject){
        //转int
        int grades1=Integer.parseInt(grades);
        int grade=selectStuDataService.selectsGrade(grades1);//grade年级
        TongJiTuData t=selectStuDataService.selectsClassdata(grades1,grade,subject);
        return t;
    }
    //查询排名分数统计图所需数据
    @RequestMapping("/selectStuData4")
    public TongJiTuData sData4(String grades, String testNames,String subject){
        //转int
        int grades1=Integer.parseInt(grades);
        TongJiTuData t=selectStuDataService.selectsGradeRank(grades1,testNames,subject);
        return t;
    }

}
